package com.saicmotor.springboot_demo.service.impl;

import com.saicmotor.springboot_demo.config.RoleConfig;
import com.saicmotor.springboot_demo.mapper.RoleMapper;
import com.saicmotor.springboot_demo.model.Role;
import com.saicmotor.springboot_demo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;
    @Autowired
    RoleConfig roleConfig;

    @Override
    public List<Role> getAll() {
        return roleMapper.getAll();
    }

    @Override
    public void insertRoleInfo(String name) {
        roleMapper.insertRoleInfo(name);
    }

    @Override
    public void deleteByName(String name) {
        roleMapper.deleteByName(name);
    }

    @Override
    public void updateName(String newName,String oldName) {
        roleMapper.updateName(newName,oldName);
    }

    @Override
    public void createRoleTable(String tableName) {
        roleMapper.createRoleTable(tableName);
    }

    @Override
    public void initRoleTable() {
        System.out.println(roleConfig.getRole().size());
        roleConfig.getRole().forEach(role -> {
            roleMapper.insertRoleInfo(role.getName());
        });
    }
}
